package com.pearadmin.didiuser.controller;

import com.github.pagehelper.PageInfo;
import com.pearadmin.didiuser.domain.DidiUserData;
import com.pearadmin.common.tools.string.Convert;
import com.pearadmin.common.web.base.BaseController;
import com.pearadmin.common.web.domain.request.PageDomain;
import com.pearadmin.common.web.domain.response.Result;
import com.pearadmin.common.web.domain.response.module.ResultTable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import com.pearadmin.didiuser.service.IDidiUserDataService;

/**
 * 滴滴用户信息Controller
 * 
 * @author 李泓辰
 * @date 2021-07-05
 */
@RestController
@RequestMapping("/didiuser/didiuserData")
public class DidiUserDataController extends BaseController
{
    private String prefix = "didiuser/didiuserData";

    @Autowired
    private IDidiUserDataService didiUserDataService;

    @GetMapping("/main")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/main','didiuser:didiuserData:main')")
    public ModelAndView main()
    {
        return jumpPage(prefix + "/main");
    }

    /**
     * 查询滴滴用户信息列表
     */
    @ResponseBody
    @GetMapping("/data")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/data','didiuser:didiuserData:data')")
    public ResultTable list(@ModelAttribute DidiUserData didiUserData, PageDomain pageDomain)
    {
        PageInfo<DidiUserData> pageInfo = didiUserDataService.selectDidiUserDataPage(didiUserData,pageDomain);
        return pageTable(pageInfo.getList(),pageInfo.getTotal());
    }

    /**
     * 新增滴滴用户信息
     */
    @GetMapping("/add")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/add','didiuser:didiuserData:add')")
    public ModelAndView add()
    {
        return jumpPage(prefix + "/add");
    }

    /**
     * 新增保存滴滴用户信息
     */
    @ResponseBody
    @PostMapping("/save")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/add','didiuser:didiuserData:add')")
    public Result save(@RequestBody DidiUserData didiUserData)
    {
        return decide(didiUserDataService.insertDidiUserData(didiUserData));
    }

    /**
     * 修改滴滴用户信息
     */
    @GetMapping("/edit")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/edit','didiuser:didiuserData:edit')")
    public ModelAndView edit(String userId, ModelMap mmap)
    {
        DidiUserData didiUserData = didiUserDataService.selectDidiUserDataById(userId);
        mmap.put("didiUserData", didiUserData);
        return jumpPage(prefix + "/edit");
    }

    /**
     * 修改保存滴滴用户信息
     */
    @ResponseBody
    @PutMapping("/update")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/edit','didiuser:didiuserData:edit')")
    public Result update(@RequestBody DidiUserData didiUserData)
    {
        return decide(didiUserDataService.updateDidiUserData(didiUserData));
    }

    /**
     * 删除滴滴用户信息
     */
    @ResponseBody
    @DeleteMapping( "/batchRemove")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/remove','didiuser:didiuserData:remove')")
    public Result batchRemove(String ids)
    {
        return decide(didiUserDataService.deleteDidiUserDataByIds(Convert.toStrArray(ids)));
    }

    /**
     * 删除
     */
    @ResponseBody
    @DeleteMapping("/remove/{userId}")
    @PreAuthorize("hasPermission('/didiuser/didiuserData/remove','didiuser:didiuserData:remove')")
    public Result remove(@PathVariable("userId") String userId)
    {
        return decide(didiUserDataService.deleteDidiUserDataById(userId));
    }
}
